package com.sskj.mine.presenter;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.SPConfig;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.mine.http.HttpConfig;
import com.sskj.mine.ui.activity.BindMobileActivity;
import com.sskj.mine.ui.activity.UnBindEmailActivity;


public class UnBindEmailPresenter extends BasePresenter<UnBindEmailActivity> {

    /**
     * 获取邮箱验证码
     *
     * @return
     */
    public void sendEmailCode(String email) {
        httpService.sendEmailCode(email)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.getMsg());
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.sendCodeOk();
                        } else {
                            mView.sendCodeError();
                        }
                    }

                    @Override
                    public void onError(Response<HttpData> response) {
                        mView.sendCodeError();
                        super.onError(response);
                    }
                });
    }

    /**
     * 验证邮箱
     */
    public void unbindMobile(String mobile, String code) {
        httpService.unBindMobile(mobile, code)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.getMsg());
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.onResponseSuccess();
                        }
                    }
                });
    }

}
